<?php

/**
* SlideNav.class.php
*
* Concrete page module responsable for creating slide nav
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/

require_once("framework/PageModule.class.php");

// {{{ SlideNav

class SlideNav extends PageModule 
{
    // {{{ Class operations 

    // {{{ getContent

    /**
    * Function returns page content
    *
    */

    function getContent()
    {

        $options = &PEAR::getStaticProperty('CONFIG_INI','TEMPLATES'); 

        $tpl = new HTML_Template_IT($options["templates_dir"]);
        $tpl->loadTemplatefile("slide_nav.tpl.xhtml",true,true);
          
        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN'); 
        $dbh = new PDO($options['dsn_string']);
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

        $sth = $dbh->prepare("SELECT `order`,guide_id FROM slide WHERE rowid = :id ");
        $sth->bindParam(':id', $_GET['id'],PDO::PARAM_INT);
        $sth->execute();
        $currentSlideData = $sth->fetch(PDO::FETCH_ASSOC);
        
        $sth = $dbh->prepare("SELECT rowid FROM slide WHERE `order` = :order - 1 AND guide_id = :guide_id");
        $sth->bindParam(':order', $currentSlideData['order'], PDO::PARAM_INT);
        $sth->bindParam(':guide_id', $currentSlideData['guide_id'] ,PDO::PARAM_INT);

        $sth->execute();
        $row = $sth->fetch(PDO::FETCH_ASSOC);

        if( isset($row['rowid']) )
        {
            $tpl->setCurrentBlock('left');
            $tpl->setVariable('URL',$global['service_url'].'?cmd=ShowSlide&id='.$row['rowid'].'&guide_id='.$currentSlideData['guide_id']);
            $tpl->setVariable('LABEL',_('poprzednia lokalizacja'));
            $tpl->parseCurrentBlock();
        }
        
        $sth = $dbh->prepare("SELECT rowid FROM slide WHERE `order` = :order + 1 AND guide_id = :guide_id");
        $sth->bindParam(':order', $currentSlideData['order'], PDO::PARAM_INT);
        $sth->bindParam(':guide_id', $currentSlideData['guide_id'] ,PDO::PARAM_INT);
        $sth->execute();
        $row = $sth->fetch(PDO::FETCH_ASSOC);

        $options = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');

        if(  isset($row['rowid']) )
        {
            $tpl->setCurrentBlock('right');
            $tpl->setVariable('URL',$global['service_url'].'?cmd=ShowSlide&id='.$row['rowid'].'&guide_id='.$currentSlideData['guide_id']);
            $tpl->setVariable('LABEL',_('następna lokalizacja'));
            $tpl->parseCurrentBlock();
        }
        return $tpl->get();
    }
    
    // }}}

    // }}}
}

// }}} 

?>
